//
//  PresentationController.m
//  自定义转场动画
//
//  Created by zxy on 2019/4/18.
//  Copyright © 2019 zxy. All rights reserved.
//

#import "PresentationController.h"
@interface PresentationController()
@property(nonatomic,strong)UIView *maskView;
@end
@implementation PresentationController

-(UIView *)maskView{
    if(!_maskView){
        _maskView = [[UIView alloc]init];
        _maskView.frame = [UIScreen mainScreen].bounds;
        _maskView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
    }
    return _maskView;
}

#pragma mark -UIViewControllerTransitioningDelegate

- (void)presentationTransitionDidEnd:(BOOL)completed {
    
}

///presentedViewController:要被展示的控制器   presentingViewController: 源控制器
-(instancetype)initWithPresentedViewController:(UIViewController *)presentedViewController presentingViewController:(UIViewController *)presentingViewController{
   self = [super initWithPresentedViewController:presentedViewController presentingViewController:presentingViewController];
    if(self){
    }
    return self;
}

-(void)containerViewWillLayoutSubviews{
    [super containerViewWillLayoutSubviews];
    //设置弹出视图大小
    self.presentedView.frame = self.presentFrame;
    ///添加遮罩view
    [self.containerView insertSubview:self.maskView atIndex:0];
    //添加手势
    UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissViewController)];
    [self.maskView addGestureRecognizer:ges];
    self.maskView.userInteractionEnabled = YES;
}
-(void)dismissViewController{
    [self.presentedViewController dismissViewControllerAnimated:NO completion:nil];
}

@end
